package com.hengpeng.msls.controller;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hengpeng.common.util.DateTimeUtil;
import com.hengpeng.itfinbase.persist.BorrowInfo;
import com.hengpeng.itfinbase.persist.UserInfo;

@Controller
@RequestMapping("/contract")
public class ProjectContractController extends BaseController {

    @RequestMapping("/projectContract")
    public String ProjectContract(String borrowInfoId, ModelMap map) {
        if (StringUtils.isEmpty(borrowInfoId)) {
            return returnErrorPage(map);
        }
        BorrowInfo borrowInfo = serviceFactory.getBorrowInfoService().getBorrowInfo(Long.parseLong(borrowInfoId), null);
        UserInfo userInfo = serviceFactory.getUserInfoService().getUserInfoById(borrowInfo.getBorrowUserId());
        // 合同编号
        String id = borrowInfo.getId() == null ? "" : borrowInfo.getId().toString();
        // 签约日期
        String contractDate = DateTimeUtil.formatShortStr(new Date());
        // 借款方
        String loanName = userInfo.getRealName();
        // 身份证号
        String cardNumber = userInfo.getCardNumber();
        // 管理方
        String name = borrowInfo.getBorrowName();
        // 营业执照号码
        String busiCode = userInfo.getBusiCode();
        // 借款用途:[purpose_name]
        String userFor = borrowInfo.getUserFor();
        // 借款本金（人民币）:￥[amount]元
        String borrowMoney = borrowInfo.getBorrowMoney() + "";
        // 年利率：[apr]
        String borrowRate = borrowInfo.getBorrowRate() + "";

        // 借款期限:[period unit]
        String durType = borrowInfo.getDurType() + "";// 周期类型
        String borrowDuration = borrowInfo.getBorrowDuration() + "";
        // 应偿还本息合计（人民币）:￥[capital_interest_sum]元
        // 还款方式:[repayment_name]
        String repaymentType = borrowInfo.getRepaymentType() + "";
        // 还款截止日期：[repayment_time]
        String bidStopTime = DateTimeUtil.formatShortStr(borrowInfo.getBidStopTime());

        map.put("id", id);
        map.put("contractDate", contractDate);
        map.put("loanName", loanName);
        map.put("cardNumber", cardNumber);
        map.put("name", name);
        map.put("busiCode", busiCode);
        map.put("userFor", userFor);
        map.put("borrowMoney", borrowMoney);
        map.put("contractDate", contractDate);
        map.put("borrowRate", borrowRate);
        map.put("durType", durType);
        map.put("borrowDuration", borrowDuration);
        map.put("repaymentType", repaymentType);
        map.put("bidStopTime", bidStopTime);
        return "/projectContract.jsp";
    }
}
